// packageA/member/wechatRecord/wechatRecord.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    total_page: 0,
    isLoadMore: true,

    list: [],
    new_wx_transfer_page_name: "提现到微信确认收款"
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let language = wx.getStorageSync('langIndex');
    this.setData({
      'language': language.en
    });
    this.init();
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  toWechat(e) {
    console.log(e)
    let {
      item
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/packageA/member/wechatWithdrawal/wechatWithdrawal?id=${item.withdraw_sn}&orderType=love`,
    })
  },
  init() {
    this.setData({
      page: 1,
      total_page: 0,
    })
  },
  async getData(key) {
    let _json = {}
    if (key == 'more') {
      if (!this.data.isLoadMore) return
      this.data.isLoadMore = true
      if (this.data.page >= this.data.last_page) {
        return
      }
      this.setData({
        page: this.data.page + 1
      })

    }
    let {
      data
    } = await app._postNetWork({
      url: app.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.wx-transfer.index"),
      data: _json,
    })
    if (data.result) {
      this.data.isLoadMore = true;
      wx.setNavigationBarTitle({
        title: data.data.new_wx_transfer_page_name,
      })
      if (key == 'more') {
        this.setData({
          list: this.data.list.concat(data.data.data)
        })
        return
      }
      this.setData({
        list: data.data.data,
        total_page: data.data.last_page,
        isLoadMore: true,
      })

    } else {
      this.setData({
        page: this.data.page - 1
      })
      this.data.isLoadMore = false;
      app.tips(data.msg)
    }
  }
})